package zjs.dc.controller;

import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.SparkSession;

/**
 * @Class:
 * @Author: guoml
 * @Description: 针对企查查t_ipo_company_important_dwdb表和聚源LC_Warrant表进行数据映射开发
 * @Date: 2021/12/7 12:51
 */

public class TIpoCompanyImportantDwdb {
    public static void main(String[] args) {
        SparkSession spark = SparkSession.builder().appName("t_ipo_company_important_dwdb").enableHiveSupport().getOrCreate();
        spark.sparkContext().setLogLevel("ERROR");
        //获取中数增量数据表中的新增数据（left join）
        Dataset<Row> insert_data = spark.sql("SELECT md5(a.ID),\n" +
                "       b.SecuCode,\n" +
                "       a.InfoPublDate,\n" +
                "       a.GuarantorCompany,\n" +
                "       a.SecuredParty,\n" +
                "       '' as secured_type,\n" +
                "       a.LatestGuaranteeSum,\n" +
                "       c.MS,\n" +
                "       a.GuaranteeTerm,\n" +
                "       a.GuaranteeBeginDate,\n" +
                "       a.GuaranteeEndDate,\n" +
                "       '' as is_finished,\n" +
                "       '' as is_transactions,\n" +
                "       '' as transaction_date,\n" +
                "       a.EventContent,\n" +
                "       '' as reporting_date,\n" +
                "       '' as reporting_type,\n" +
                "       '' as created_date,\n" +
                "       '' as updated_date,\n" +
                "       '' as encrypt_key,\n" +
                "       regexp_replace(current_date(),'-',''),\n" +
                "       \"1\" as isadd\n" +
                "FROM\n" +
                "  (select * from a_dc_ep_ods.LC_Warrant)a\n" +
                "INNER JOIN\n" +
                "  (select * from a_dc_ep_ods.SecuMain where ListedState = 1 and SecuCategory = 1) b on a.CompanyCode = b.CompanyCode\n" +
                "LEFT JOIN\n" +
                "  (select * from a_dc_ep_ods.CT_SystemConst where LB=1068) c on a.CurrencyUnit = c.DM");
        insert_data.createOrReplaceTempView("tmp_t_ipo_company_important_dwdb1");
        spark.sql("insert overwrite table a_dc_ep_incr.t_ipo_company_important_dwdb select * from tmp_t_ipo_company_important_dwdb1");
        spark.stop();
    }
}
